<?php
   require ( "../../admin/config.php" );
  require ( "../../$FunctionFolder/CGI.php" );
  require ( "../../$FunctionFolder/SQL.php" );
  
  $cgi = new CGI ();
  $sql = new SQL ( $DBusername, $DBpassword, $server, $database );

  if ( ! $sql->isConnected () )
  {
    die ( $DatabaseError );
  }  
   require ( "../../$FunctionFolder/CSQL.php" );
   require ( "../../$LanguageFolder/$language_pack/index.php" );  
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html <?php echo MAIN_HTML_PARAMS; ?>>
<head>
<title><?php echo MAIN_TITLE; ?></title>
<meta http-equiv="Content-Type" content="text/html; charset=<?php echo MAIN_CHARSET; ?>"> 
<LINK REL="STYLESHEET" HREF="../../includes/lang/<?php print "$language_pack"; ?>/style.css"> 
</head><body margin="0" onLoad="window.print()"></body>
<?php 


  $sortBy = $cgi->getValue ( "sortBy" );
  $sortByType = "ASC";
  $page = intval ( $cgi->getValue ( "page" ) );
  
  if ( ! $sortBy )
  {
    $sortBy = "id";
  }

    $query = "
      SELECT
        p.id                AS id,
        p.propertyoption    AS propertyoption,
        p.propertyprice     AS propertyprice,
        p.propertyaddress   AS propertyaddress,
        pl.propertylocation AS propertylocation,
        ps.propertystatus   AS propertystatus,
        pt.propertytype     AS propertytype,
        p.propertyref       AS propertyref,
        p.propertybedrooms  AS propertybedrooms,
        p.propertyphoto1    AS propertyphoto1,
        p.shortdescription  AS shortdescription,
        p.longdescription   AS longdescription
      FROM
        " . $property_table . " p
        INNER JOIN
        " . $propertytypes_table . " pt ON (p.propertytype=pt.id)
        INNER JOIN
        " . $propertylocations_table . " pl ON (p.propertylocation=pl.id)
        INNER JOIN
        " . $propertystatus_table . " ps ON (p.propertystatus=ps.id)
      WHERE
        p.propertyshow=1
      ";

    // set the query ordering
    if ( isset ( $sortBy ) && $sortBy != "" )
      $query .= "ORDER BY p." . $sortBy . " " .
           ( "a" == strtolower ( substr ( $sortByType, 0, 1 ) ) ?
             "ASC" : "DESC" );
    
    $results = $sql->execute ( $query, SQL_RETURN_ASSOC );
   $total_results = sizeof ( $results );

  
  if ( $total_results )
  {


    ?>

<br>
<p align="center">Property Listing Report Created on <?php echo "$dateadded"; ?></p>

<?php
  
    for ( $i = 0; $i < $total_results; ++$i )
    {
      $row              = $results [ $i ];
      $id               = $row [ "property_id" ];
      $propertyroption  = $row [ "propertyoption" ];
      $propertyref      = $row [ "propertyref" ];
      $propertyphoto1   = $row [ "propertyphoto1" ];
      $propertyaddress  = $row [ "propertyaddress" ];
      $propertyviews    = $row [ "propertyviews" ];
      $propertytype     = $row [ "propertytype" ];
      $propertylocation = $row [ "propertylocation" ];
      $propertyprice    = number_format ( $row [ 'propertyprice' ], PRICE_FORMAT ); 

      ?>
<TABLE WIDTH="100%" CELLSPACING="1" cellpadding="5" BGCOLOR="#CCCCCC" align="center" border="1">
<TR VALIGN="MIDDLE">
<TD BGCOLOR="#F3F3F3" VALIGN="MIDDLE" ALIGN="CENTER" width="125"><P><B>Photo</B></P></TD>
<TD BGCOLOR="#F3F3F3" VALIGN="MIDDLE" ALIGN="left" width="100%"><P><B>Property Details</B></P></TD>
<TD BGCOLOR="#F3F3F3" VALIGN="MIDDLE" ALIGN="CENTER" width="125"><P><B>Price</B></P></TD>
<TD BGCOLOR="#F3F3F3" VALIGN="MIDDLE" ALIGN="CENTER" width="125"><P><B>Views</B></P></TD>

</TR>
<TR VALIGN="MIDDLE">
<TD BGCOLOR="#FFFFFF" VALIGN="MIDDLE" ALIGN="CENTER"><?php if ($propertyphoto1) {print "<img src=\"$ImageURL$propertyphoto1\" width=\"125\" height=\"85\">"; }?></TD>
<TD BGCOLOR="#FFFFFF" VALIGN="MIDDLE" ALIGN="top">
<P><b>Property Ref:</b> <?php echo $cgi->htmlEncode ( $propertyref ); ?><br>
<b>Property Type:</b> <?php echo $cgi->htmlEncode ( $propertytype ); ?><br>
<b>Address:</b> <?php echo $cgi->htmlEncode ( $propertyaddress ); ?>, <?php echo $cgi->htmlEncode ( $propertylocation ); ?></P></TD>
<TD BGCOLOR="#FFFFFF" VALIGN="MIDDLE" ALIGN="CENTER"><P>
<?php if ($cgi->htmlEncode ( $propertyoption ) == "S") {echo "For Sale";} ?>
<?php if ($cgi->htmlEncode ( $propertyoption ) == "R") {echo "For Rent";} ?>
<br>
<?php echo CURRENCY; ?><?php echo $cgi->htmlEncode ( $propertyprice ); ?></P></TD>
<TD BGCOLOR="#FFFFFF" VALIGN="MIDDLE" ALIGN="CENTER"><p><?php echo $cgi->htmlEncode ( $propertyviews ); ?></p></TD>

</TR></table><br>
<?php
    }
  }

?>
<br>
<br>
</html>